

let Charts = require('../../../utils/wxcharts-min.js');
//引入
Page({
  data: {
    nav: 0,
    nav3: [],
    nav1: [],
    nav2: [],
    m: [],
    d: [],
    w: [],
    sysWidth: 1,
    pages: 1,
    total: 0,

  },
  async onLoad () {
    this.setData({
      sysWidth: wx.getSystemInfoSync().windowWidth / 750
    })
    await this.getNav0()
  },
  async navTo (e) {
    const nav = e.currentTarget.dataset.index;
    this.setData({ nav });
    switch (nav) {
      case 0:
        await this.getNav0()
        break;
      case 1:
        await this.getNav1()
        break;
      case 2:
        await this.getNav2()
        break;
      case 3:
        await this.nav3loadNoce()
        break;
      default:
        break;
    }
  },
  async getNav1 () {
    wx.showLoading({
      title: '加载员工中',
    })
    wx.showNavigationBarLoading()
    const nav1 = await getApp().httpModule.getSuccessAppuser();
    this.setData({ nav1: nav1.data.data })

    wx.hideLoading();
    wx.hideNavigationBarLoading()
  },
  async getNav2 () {
    wx.showLoading({
      title: '加载审核管理中',
    })
    wx.showNavigationBarLoading()
    const nav2 = await getApp().httpModule.getSuccessAudit();
   
    this.setData({ nav2: nav2.data.data })
    console.log(nav2)
    wx.hideLoading();
    wx.hideNavigationBarLoading()
  },
  async getNav0 () {
    //获取所有统计数据
    wx.showLoading({
      title: '加载统计数据中',
    })
    wx.showNavigationBarLoading()
    const m = await this.getM();
    const d = await this.getD();
    const w = await this.getW();
    console.log(m.data.data)
    console.log(w.data.data)
    console.log(d.data.data)
    this.setData({
      m: m.data.data,
      d: d.data.data,
      w: w.data.data
    });
    //day
    new Charts({
      canvasId: 'pie1',
      type: 'ring',
      series: [{
        name: '已签到',
        data: this.data.d[0].signPeopleNum,
        color: '#78D09E'
      }, {
        name: '未签到',
        color: '#3D4061',
        data: this.data.d[0].countPeopleNum - this.data.d[0].signPeopleNum,
      }],
      disablePieStroke: false,
      title: {
        name: parseInt((this.data.d[0].signPeopleNum / this.data.d[0].countPeopleNum) * 100) + '%',
        color: '#ffffff',
        fontSize: 30 * this.data.sysWidth
      },
      subtitle: {
        color: '#ffffff',
        name: '上午',
        fontSize: 20 * this.data.sysWidth
      },
      extra: {
        ringWidth: 22 * this.data.sysWidth,
        legendTextColor: '#ffffff'
      },
      legend: true,
      background: "#45476E",
      width: 300 * this.data.sysWidth,
      height: 300 * this.data.sysWidth,
      dataLabel: false,
      disablePieStroke: true
    });
    new Charts({
      canvasId: 'pie2',
      type: 'ring',
      series: [{
        name: '已签到',
        data: this.data.d[1].signPeopleNum,
        color: '#78D09E'
      }, {
        name: '未签到',
        color: '#3D4061',
        data: this.data.d[1].countPeopleNum - this.data.d[1].signPeopleNum,
      }],
      disablePieStroke: false,
      title: {
        name: parseInt((this.data.d[1].signPeopleNum / this.data.d[1].countPeopleNum) * 100) + '%',
        color: '#ffffff',
        fontSize: 30 * this.data.sysWidth
      },
      subtitle: {
        color: '#ffffff',
        name: '下午',
        fontSize: 20 * this.data.sysWidth
      },
      extra: {
        ringWidth: 22 * this.data.sysWidth,
        legendTextColor: '#ffffff'
      },
      legend: true,
      background: "#45476E",
      width: 300 * this.data.sysWidth,
      height: 300 * this.data.sysWidth,
      dataLabel: false,
      disablePieStroke: true
    });
    //w
    new Charts({
      canvasId: 'pie3',
      type: 'ring',
      series: [{
        name: '已签到',
        data: this.data.w[0].signPeopleNum,
        color: '#78D09E'
      }, {
        name: '未签到',
        color: '#3D4061',
        data: this.data.w[0].countPeopleNum - this.data.w[0].signPeopleNum,
      }],
      disablePieStroke: false,
      title: {
        name: parseInt((this.data.w[0].signPeopleNum / this.data.w[0].countPeopleNum) * 100) + '%',
        color: '#ffffff',
        fontSize: 30 * this.data.sysWidth
      },
      subtitle: {
        color: '#ffffff',
        name: '上午',
        fontSize: 20 * this.data.sysWidth
      },
      extra: {
        ringWidth: 22 * this.data.sysWidth,
        legendTextColor: '#ffffff'
      },
      legend: true,
      background: "#45476E",
      width: 300 * this.data.sysWidth,
      height: 300 * this.data.sysWidth,
      dataLabel: false,
      disablePieStroke: true
    });
    new Charts({
      canvasId: 'pie4',
      type: 'ring',
      series: [{
        name: '已签到',
        data: this.data.w[1].signPeopleNum,
        color: '#78D09E'
      }, {
        name: '未签到',
        color: '#3D4061',
        data: this.data.w[1].countPeopleNum - this.data.w[1].signPeopleNum,
      }],
      disablePieStroke: false,
      title: {
        name: parseInt((this.data.w[1].signPeopleNum / this.data.w[1].countPeopleNum) * 100) + '%',
        color: '#ffffff',
        fontSize: 30 * this.data.sysWidth
      },
      subtitle: {
        color: '#ffffff',
        name: '下午',
        fontSize: 20 * this.data.sysWidth
      },
      extra: {
        ringWidth: 22 * this.data.sysWidth,
        legendTextColor: '#ffffff'
      },
      legend: true,
      background: "#45476E",
      width: 300 * this.data.sysWidth,
      height: 300 * this.data.sysWidth,
      dataLabel: false,
      disablePieStroke: true
    });
    //m
    new Charts({
      canvasId: 'pie5',
      type: 'ring',
      series: [{
        name: '已签到',
        data: this.data.m[0].signPeopleNum,
        color: '#78D09E'
      }, {
        name: '未签到',
        color: '#3D4061',
        data: this.data.m[0].countPeopleNum - this.data.m[0].signPeopleNum,
      }],
      disablePieStroke: false,
      title: {
        name: parseInt((this.data.m[0].signPeopleNum / this.data.m[0].countPeopleNum) * 100) + '%',
        color: '#ffffff',
        fontSize: 30 * this.data.sysWidth
      },
      subtitle: {
        color: '#ffffff',
        name: '上午',
        fontSize: 20 * this.data.sysWidth
      },
      extra: {
        ringWidth: 22 * this.data.sysWidth,
        legendTextColor: '#ffffff'
      },
      legend: true,
      background: "#45476E",
      width: 300 * this.data.sysWidth,
      height: 300 * this.data.sysWidth,
      dataLabel: false,
      disablePieStroke: true
    });
    new Charts({
      canvasId: 'pie6',
      type: 'ring',
      series: [{
        name: '已签到',
        data: this.data.m[1].signPeopleNum,
        color: '#78D09E'
      }, {
        name: '未签到',
        color: '#3D4061',
        data: this.data.m[1].countPeopleNum - this.data.m[1].signPeopleNum,
      }],
      disablePieStroke: false,
      title: {
        name: parseInt((this.data.m[1].signPeopleNum / this.data.m[1].countPeopleNum) * 100) + '%',
        color: '#ffffff',
        fontSize: 30 * this.data.sysWidth
      },
      subtitle: {
        color: '#ffffff',
        name: '下午',
        fontSize: 20 * this.data.sysWidth
      },
      extra: {
        ringWidth: 22 * this.data.sysWidth,
        legendTextColor: '#ffffff'
      },
      legend: true,
      background: "#45476E",
      width: 300 * this.data.sysWidth,
      height: 300 * this.data.sysWidth,
      dataLabel: false,
      disablePieStroke: true
    });
    wx.hideLoading();
    wx.hideNavigationBarLoading()
  },
  async getW () {
    const data = {
      type: 3,
      time: new Date().format('yyyy-MM-dd')
    }
    return getApp().httpModule.statisticsSign(data)
  },
  async getD () {
    const data = {
      type: 1,
      time: new Date().format('yyyy-MM-dd')
    }
    return getApp().httpModule.statisticsSign(data)
  },
  async getM () {
    const data = {
      type: 2,
      time: new Date().format('yyyy-MM-dd')
    }
    return getApp().httpModule.statisticsSign(data)
  },
  async nav3loadNoce () {
    wx.showNavigationBarLoading()
    wx.showLoading({
      title: '刷新中',
    })
    this.setData({
      nav3: [],
      total: 0,
      pages: 1
    });
    await this.loadMore()
  },
  async loadMore () {
    wx.showNavigationBarLoading()
    wx.showLoading({
      title: '加载更多',
    })
    let pages = this.data.pages;
    const p = {
      page: this.data.pages,
      limit: 100,
      time: new Date().format('yyyy-MM')
    }
    const data = await getApp().httpModule.signManage(p)
    let list = data.data.data;
    console.log(data)
    const listData = this.data.nav3;
    for (let i in list) {
      listData.push(list[i])
    }
  
    const total = data.data.count?data.data.count:0;
    this.setData({ nav3: listData, total });
    console.log(listData)
    wx.hideLoading();
    wx.stopPullDownRefresh();
    wx.hideNavigationBarLoading();
  },
  async onReachBottom () {
    let pages = this.data.pages;
    const total = this.data.total;
    if ((pages) * 20 < total) {
      pages++;
      this.setData({ pages })
      await this.loadMore()
    }
  },
  toDetail (e) {
    const value = e.currentTarget.dataset.detail;
    console.log(value);
    wx.navigateTo({
      url: `/pages/mar/signDetail/index?id=${value.id}&uname=${value.uname}`,
    })
  },
  async handAudit (e) {
    // e.currentTarget.dataset
    console.log(e)
    let auditObj = {
      id:e.currentTarget.dataset.id,
      state:e.currentTarget.dataset.state,
    }

    wx.showLoading({
      title: '审核中',
    })

    const nav2 = await getApp().httpModule.getSuccessIsAudit(auditObj);
   console.log(nav2)
    if (nav2.data.code == '200') {
      this.getNav2()
    }
 

    wx.hideLoading();
    // wx.hideNavigationBarLoading()
  }
})